﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.Profile;
using System.Data;
using HySoft.Cash.Business;
using System.Data.SqlClient;
using HySoft.Cash.BaseClass;
using System.Configuration;
using System.Web.UI.WebControls;
using HySoft.Cash.Structure;

namespace PayRoller.Member
{
    public class EmpList : MemberParent, IRequiresSessionState
    {
        // Fields
        protected Button bnSearch;
        public DataTable dtEmpList = new DataTable();
        protected TextBox txtEmpName;
        protected TextBox txtOrgEmpSid;
        protected TextBox txtSid;

        // Methods
        protected void bnSearch_Click(object sender, EventArgs e)
        {
            GetEmpList();
        }

        private void GetEmpList()
        {
            using (TempinfoBN obn = new TempinfoBN(this.Page))
            {
                obn.QueryOrgSid(Convert.ToInt32(base.OrgSid));
                if (this.txtOrgEmpSid.Text != "")
                {
                    obn.QueryOrgEmpSid(this.txtOrgEmpSid.Text);
                }
                if (this.txtEmpName.Text != "")
                {
                    obn.QueryEmpName(this.txtEmpName.Text);
                }

                string sidString = this.txtSid.Text.Trim();
                if (sidString != string.Empty)
                {
                    int tempSid = 0;
                    bool successful = int.TryParse(sidString, out tempSid);
                    if (successful == true)
                    {
                        obn.QuerySid(tempSid);
                    }
                }

                /*不显示被删除的用户*/
                obn.Filter = string.Format("IsValid!={0}", (int)EmpStatuses.Deleted);

                this.dtEmpList = obn.GetList();
            }
        }

        public string GetSumPaymentByEmp(int EmpSid)
        {
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@EmpSid", EmpSid) };
            DataTable table = SqlHelper.ExecuteDataset(ConfigurationManager.AppSettings["SQLConnString"], CommandType.StoredProcedure, "GetSumPaymentByEmp", commandParameters).Tables[0];
            if ((table.Rows.Count > 0) && (((table.Rows[0][0].ToString() != null) && (table.Rows[0][0].ToString() != "&nbsp;")) && (table.Rows[0][0].ToString() != "")))
            {
                return table.Rows[0][0].ToString();
            }
            return "0.00";
        }

        protected override void OnInit(EventArgs e)
        {
            base.CheckLogin();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                GetEmpList();
            }
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }
}
